# import time
# from functools import wraps
#
# from app.utils.logger import get_logger
#
#
# # ========== 同步版本（之前已实现）==========
# def timing_decorator(func):
#     original_func = func
#     if isinstance(func, (staticmethod, classmethod)):
#         original_func = func.__func__
#
#     @wraps(original_func)
#     def wrapper(*args, **kwargs):
#         start = time.perf_counter()
#         try:
#             return original_func(*args, **kwargs)
#         finally:
#             elapsed_ms = (time.perf_counter() - start) * 1000
#             _log_timing(original_func, elapsed_ms)
#
#     if isinstance(func, staticmethod):
#         return staticmethod(wrapper)
#     elif isinstance(func, classmethod):
#         return classmethod(wrapper)
#     else:
#         return wrapper
#
#
# # ========== 弌步版本（新增）==========
# def async_timing_decorator(func):
#     """
#     用于 async def 函数的计时装饰器。
#     支持普通异步函数、异步实例方法、@classmethod、@staticmethod。
#     """
#     original_func = func
#     if isinstance(func, (staticmethod, classmethod)):
#         original_func = func.__func__
#
#     @wraps(original_func)
#     async def async_wrapper(*args, **kwargs):
#         start = time.perf_counter()
#         try:
#             result = await original_func(*args, **kwargs)
#             return result
#         finally:
#             elapsed_ms = (time.perf_counter() - start) * 1000
#             _log_timing(original_func, elapsed_ms)
#
#     # 保持原始类型
#     if isinstance(func, staticmethod):
#         return staticmethod(async_wrapper)
#     elif isinstance(func, classmethod):
#         return classmethod(async_wrapper)
#     else:
#         return async_wrapper
#
#
# # ========== 公共日志函数 ==========
# def _log_timing(func, elapsed_ms: float):
#     """统一的日志记录逻辑"""
#     module = func.__module__
#     func_name = func.__name__
#
#     if '.' in func.__qualname__ and '<locals>' not in func.__qualname__:
#         class_name = func.__qualname__.rsplit('.', 1)[0]
#         full_name = f"{module}.{class_name}.{func_name}"
#     else:
#         full_name = f"{module}.{func_name}"
#
#     # 获取 logger 实例而不是函数
#     logger = get_logger()
#     logger.info(f"⏱️  {full_name} 执行耗时: {elapsed_ms:.2f} ms")
